package com.lc.listdemo;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

/**
 * Created by Administrator on 2017/5/4.
 */

public class ListViewDemoAdapter extends BaseAdapter{
    Context context;
    List<String> strings;
    public ListViewDemoAdapter(Context context,List<String> strings){
        this.context=context;
        this.strings=strings;
    }

    @Override
    public int getCount() {
        return strings.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
//        View view = LayoutInflater.inflate(R.layout.list_item,null);

        ViewHolder holder = null;
        if(convertView ==null){
            holder =new ViewHolder();
            convertView =LayoutInflater.from(context).inflate(R.layout.list_item,null);
            holder.text_item= (TextView) convertView.findViewById(R.id.text_item);
            convertView.setTag(holder);
        }
            holder.text_item.setText(strings.get(position));
       


   //     TextView title = (TextView)view.findViewById(R.id.text_item);




        return convertView;
    }


    public static class ViewHolder{
        TextView text_item;
    }
}
